package com.lmonkey.servlet.my;

import com.lmonkey.servic.COMMENTDao;
import com.lmonkey.servic.ORDERDao;
import com.lmonkey.servic.PRODUCTDao;
import com.lmonkey.shop.ORDER;
import com.lmonkey.shop.PRODUCT;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.zip.DataFormatException;
import java.util.Date;

import java.text.DateFormat;

@WebServlet("/shangc/dochage")
public class DoChage extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置字符集
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");

        //获取参数
        String oid = request.getParameter("oid");
        String desc = request.getParameter("desc");

        //将该订单的状态改为4；
        ORDERDao.update(oid);

        ORDER dd = ORDERDao.selectByid(oid);
        //查找商品的id
        PRODUCT p = PRODUCTDao.selectByname(dd.getOrder_p_filename());

        //添加评论
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());

        COMMENTDao.add(dd.getOrder_u_id(),desc,formatter.format(date),p.getProduct_id(),dd.getOrder_p_name(),dd.getOrder_p_price(),dd.getOrder_p_filename());

        response.sendRedirect("myprodselect");
    }
}
